public class W12 {
    public int pivotIndex(int[] nums) {
        int length=nums.length;
        for(int i=1;i<length;i++){
            nums[i]+=nums[i-1];
        }
        int total=nums[length-1];
        if(total==nums[0]){
            return 0;
        }
        if(nums[length-2]==0){
            return length-1;
        }
        for(int i=1;i<length-1;i++){
            if(nums[i-1]==total-nums[i]){
                return i;
            }
        }
        return -1;
    }
}
